package com.hunttown.mes.dao;

import com.hunttown.common.dao.base.BaseDao;
import com.hunttown.common.domain.Query;
import com.hunttown.mes.domain.CustomerLocation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * created by wangjunfu on 2021-06-08 14:12:18
 */
@Repository
public class CustomerLocationDao extends BaseDao {
    private static final Logger logger = LoggerFactory.getLogger(CustomerLocationDao.class);

    public CustomerLocation insert(final CustomerLocation customerLocation) {
        insert("CustomerLocation.insert", customerLocation);
        return customerLocation;
    }

    public Boolean updateInfoById(final CustomerLocation customerLocation) {
        return update("CustomerLocation.updateInfoById", customerLocation) > 0;
    }

    public Boolean updateInfoByQuery(final Query query) {
        return update("CustomerLocation.updateInfoByQuery", query) > 0;
    }

    public CustomerLocation selectById(final Integer id, final Integer entId) {
        Query query = Query.noPage();
        query.put("id", id);
        query.put("entId", entId);
        return queryForObject("CustomerLocation.selectById", query);
    }

    public List<CustomerLocation> selectByQuery(final Query query) {
        return queryForList("CustomerLocation.selectByQuery", query);
    }

    public Long countByQuery(final Query query) {
        return queryForObject("CustomerLocation.countByQuery", query);
    }

    public Boolean deleteById(final Integer id, final Integer entId) {
        CustomerLocation customerLocation = new CustomerLocation();
        customerLocation.setDeleteFlag(1);
        customerLocation.setId(id);
        customerLocation.setEntId(entId);

        return update("CustomerLocation.updateInfoById", customerLocation) > 0;
    }

    //物理删除不可恢复，慎用！
    public Boolean deleteByIdForPhysical(final Integer id) {
        Query query = Query.noPage();
        query.put("id", id);
        return delete("CustomerLocation.deleteById", query) > 0;
    }
}